<?php
$local= false; 
$username = 'mg44268';
$password = 'tuoZu6za';
$connectionString = "mysql:dbname=mg44268";

if ($local) {
    $username = 'root';
    $password = '';
    $connectionString="mysql:dbname=Terenac";
}

try 
{
    $db = new PDO(
            $connectionString,
                    $username, 
                    $password);
    
    $db->setAttribute(  PDO::ATTR_ERRMODE,
                        PDO::ERRMODE_EXCEPTION);
    
    $db->setAttribute(  PDO::ATTR_DEFAULT_FETCH_MODE,
                        PDO::FETCH_NAMED);
    
    $db->exec("SET NAMES utf8");
}catch (PDOException $e) 
{
    header('Content-Type: text/plain');
    die("~ Error occured while accessing database > $e ~");
}

/*** pripremanje upita:
$q = $db->prepare("SELECT * FROM tbl WHERE id=?");
$q->execute(array($id));
*/
/*** dohvacanje po redovima:
foreach ($q as $redak) {
}
*/
/*** dohvacanje cijelog skupa rezultata:
$sve = $q->fetchAll();
*/

?>
